package com.example.lenjor.sprite.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;

import com.example.lenjor.sprite.R;
import com.example.lenjor.sprite.adapter.BeiBaoAdapter;
import com.example.lenjor.sprite.bean.BeibaoInfo;
import com.example.lenjor.sprite.util.AnimUtil;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/7/2 0002.
 */
public class BeiBaoView extends BaseView{
    private Dialog dialog;
    private ImageView iv_close;
    private GridView gridView;
    private BeiBaoAdapter beiBaoAdapter;
    //背包弹框假的数据
    private ArrayList<BeibaoInfo> beibaoData;
    public BeiBaoView(Context context) {
        super(context);
        setContextView(R.layout.view_beibao);
        initUI();
        initBeiBaoAdapter();
    }
    private void initBeiBaoAdapter(){
        beiBaoAdapter = new BeiBaoAdapter(context, getBeiBaoListData());
        gridView.setAdapter(beiBaoAdapter);

    }
    private ArrayList<BeibaoInfo> getBeiBaoListData(){
        if(beibaoData == null){
            beibaoData = new ArrayList<BeibaoInfo>();
        }
        beibaoData.add(0, new BeibaoInfo(R.mipmap.rare1,"LV 16", R.mipmap.att_earth, R.mipmap.ic_shilf, R.mipmap.a));
        beibaoData.add(1, new BeibaoInfo(R.mipmap.rare2,"LV 14", R.mipmap.att_fire, R.mipmap.ic_ssalamander, R.mipmap.b));
        beibaoData.add(2, new BeibaoInfo(R.mipmap.rare3,"LV 17", R.mipmap.att_water, R.mipmap.ic_sundine, R.mipmap.c));
        beibaoData.add(3, new BeibaoInfo(R.mipmap.rare2,"LV 15", R.mipmap.att_fire, R.mipmap.ic_undine, R.mipmap.d));
        beibaoData.add(4, new BeibaoInfo(R.mipmap.rare1,"LV 12", R.mipmap.att_earth, R.mipmap.ic_salamander, R.mipmap.a));
        beibaoData.add(5, new BeibaoInfo(R.mipmap.rare2,"LV 7", R.mipmap.att_earth, R.mipmap.ic_snrom, R.mipmap.b));
        beibaoData.add(6, new BeibaoInfo(R.mipmap.rare2,"LV 12", R.mipmap.att_fire, R.mipmap.ic_norm, R.mipmap.c));
        beibaoData.add(7, new BeibaoInfo(R.mipmap.rare3,"LV 12", R.mipmap.att_earth, R.mipmap.ic_undine, R.mipmap.d));
        beibaoData.add(8, new BeibaoInfo(R.mipmap.rare1,"LV 10", R.mipmap.att_water, R.mipmap.ic_sundine, R.mipmap.c));
        beibaoData.add(9, new BeibaoInfo(R.mipmap.rare2,"LV 9", R.mipmap.att_water, R.mipmap.ic_undine, R.mipmap.b));
        beibaoData.add(10, new BeibaoInfo(R.mipmap.rare3,"LV 19", R.mipmap.att_earth, R.mipmap.ic_ssalamander, R.mipmap.a));
        beibaoData.add(11, new BeibaoInfo(R.mipmap.rare3,"LV 19", R.mipmap.att_earth, R.mipmap.ic_undine, R.mipmap.s));
        return beibaoData;
    }
    public void show(){
        if (dialog == null){
            dialog = new Dialog(context,R.style.MyDialog);
            //-2:自适应   -1：占满
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(-2,-2);
            dialog.setContentView(view,params);
        }
        dialog.show();
    }
    @Override
    protected void initUI() {
        gridView = (GridView) findViewById(R.id.gridview);
        iv_close = (ImageView) findViewById(R.id.iv_beibao_close);
        AnimUtil.addOnTouchListener(iv_close, 0.5f, 0.5f, new AnimUtil.AnimListener() {
            @Override
            public void down(View v) {

            }

            @Override
            public void move(View v) {

            }

            @Override
            public void up(View v) {
                dialog.dismiss();
            }
        });

    }

}
